package org.train.entity;

import com.fasterxml.jackson.annotation.JsonGetter;
import lombok.Data;
import lombok.EqualsAndHashCode;

// 合同详细使用的对象
@Data
@EqualsAndHashCode(callSuper = true)
public class ProjectDetailVo extends ProjectPo{
    // 这里的数据都是总计的，不是当年的
    private Double totalBilling; // 累计开票
    private Double totalExpenditure; // 累计支出
    private Double totalFundsReceived; // 累计回款
    private Double totalAdvancePayment; // 累计预付

    // TODO 合理计算needPayment
    private Double needPayment = 0.0;  // 累计应付？

    @JsonGetter("receivable")
    public Double getReceivable(){
        return totalBilling - totalFundsReceived;
    }
    @JsonGetter("profitRate")
    public Double getProfitRate(){
        if(totalBilling == 0){
            return 0.0;
        }
        return (totalBilling - totalExpenditure) / totalBilling;
    }
    @JsonGetter("totalGrossProfit")
    public Double getTotalGrossProfit(){
        return totalBilling - totalExpenditure;
    }

    public ProjectDetailVo assignProjectPo(ProjectPo po){
        this.setId(po.getId());
        this.setContractName(po.getContractName());
        this.setContractSigner(po.getContractSigner());
        this.setProjectLeader(po.getProjectLeader());
        this.setFirstParty(po.getFirstParty());
        this.setContractStartTime(po.getContractStartTime());
        this.setContractEndTime(po.getContractEndTime());
        this.setContractAmount(po.getContractAmount());
        this.setBidFee(po.getBidFee());
        this.setBidSecurity(po.getBidSecurity());
        this.setProjectYear(po.getProjectYear());
        this.setProjectLevel(po.getProjectLevel());
        this.setResearchOffice(po.getResearchOffice());
        this.setProjectStatus(po.getProjectStatus());
        this.setContractArchiving(po.getContractArchiving());
        this.setBidSecurityReturn(po.getBidSecurityReturn());
        this.setBidFeeInvoicing(po.getBidFeeInvoicing());
        return this;
    }
}
